package zhh.tangbao.commodity.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import zhh.tangbao.commodity.entity.CommodityOrderContent;
import zhh.tangbao.commodity.manager.pickup.PickUpOrderContent;
import zhh.tangbao.commodity.vo.order.WeChatOrderContentVo;
import zhh.tangbao.wechat.vo.order.OrderContentDetailDaoVo;

import java.util.Collection;
import java.util.List;

/**
 * <p>
 * 描述
 * </p>
 *
 * @author 粥灰灰
 * <p>2023/3/5</p>
 */

@Repository
@Mapper
public interface CommodityOrderContentDao extends BaseMapper<CommodityOrderContent> {

    int insertBatchSomeColumn(Collection<CommodityOrderContent> content);

    @Select("SELECT id, commodity_machine_id, commodity_entity_id, commodity_entity_count, stock_id FROM commodity_order_content WHERE commodity_order_id = #{orderId} AND pickup_status = #{pickUpStatus}")
    List<PickUpOrderContent> listPickUpOrderContent(@Param("orderId") String orderId, @Param("pickUpStatus") Integer pickUpStatus);


    @Update("UPDATE commodity_order_content SET pickup_status = #{pickUpStatus} WHERE commodity_order_id = #{orderId} AND commodity_machine_id = #{machine};")
    int updateContentsPickupStatus(@Param("orderId") String orderId, @Param("machine") String machine, @Param("pickUpStatus") Integer pickUpStatus);

    List<WeChatOrderContentVo> listWeChatOrderContentVoByOrderIds(@Param("ids") Collection<String> orderIds);

    @Select("SELECT ce.commodity_img,ce.commodity_name,coc.commodity_entity_count,coc.commodity_entity_price,coc.commodity_content_total_price,coc.commodity_machine_id machine_id,cme.machine_name,cme.machine_img,cme.machine_position,coc.pickup_status " +
            "FROM commodity_order_content coc " +
            "JOIN commodity_entity ce ON coc.commodity_entity_id = ce.id " +
            "JOIN commodity_machine_entity cme ON coc.commodity_machine_id = cme.id " +
            "WHERE coc.commodity_order_id = #{id}")
    List<OrderContentDetailDaoVo> listOrderContentDetailVoByOrderId(@Param("id") String id);
}
